package com.example.demo.config;

import com.example.demo.model.RESTfulResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class ControllerExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public RESTfulResult<?> handleException(Exception e) {
        log.error("Controller error:", e);
        var result = new RESTfulResult<>();
        result.setCode(500);
        result.setMessage(e.getMessage());
        result.setSuccess(false);
        return result;
    }

}
